﻿using System;
using System.Collections.Generic;
using MusicStore.Entities;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;
using NUnit.Framework;

namespace MusicStore.Data.Test.Repository
{
	public class TestBase
	{
		public TestBase()
		{
			log4net.Config.XmlConfigurator.Configure();
		}

		[Test, Explicit]
		public void CreateDatabase()
		{
			var cfg = new Configuration().Configure();
			var se = new SchemaExport(cfg);
			se.Create(false, true);
		}

		protected static List<Album> CreateTestAlbums()
		{
			List<Album> albums = new List<Album>();
			for (int i = 0; i < 10; i++)
			{
				Album a = CreateTestAlbum(i);
				albums.Add(a);
			}
			return albums;
		}

		protected static Album CreateTestAlbum(int i)
		{
			Album a = new Album
			{
				Author = "Author " + i,
				Genre = "Rock",
				Label = "Label " + i,
				Note = "Note " + i,
				PublicationDate = DateTime.Now,
				Title = "Very Long Album Title " + i
			};
			for (int j = 0; j < 10; j++)
			{
				Track t = new Track
				{
					Number = j,
					Duration = "0:0:" + j,
					Title = "Title " + j
				};
				a.Tracks.Add(t);
			}
			return a;
		}

		public List<Album> FillWithSampleData()
		{
			List<Album> albums = new List<Album>();
			/*
				  * Under a blood Red Sky
				  * 
				  */
			var album = new Album( )
			{
				Title = "Under a blood Red Sky",
				Author = "U2",
				Genre = "Rock",
				Label = "Island records",
				PublicationDate = new DateTime(1983, 11, 7)
			};

			album.AddTrack(1, "Gloria", "0:4:34");
			album.AddTrack(2, "11 O'Clock Tick Tock","0:4:32");
			album.AddTrack(3, "I Will Follow", "0:3:36");
			album.AddTrack(4, "Party Girl", "0:2:52");
			album.AddTrack(5, "Sunday Bloody Sunday", "0:4:55");
			album.AddTrack(6, "The Electric Co.", "0:5:18");
			album.AddTrack(7, "New Year's Day", "0:4:29");
			album.AddTrack(8, "40", "0:3:36");

			albums.Add(album);

			/*
			 * The Dark Side of The Moon
			 * 
			 */
			album = new Album()
			{
				Title = "The Dark Side of the Moon",
				Author = "Pink Floyd",
				Genre = "Rock",
				Label = "EMI",
				PublicationDate = new DateTime(1973, 3, 24)
			};

			album.AddTrack(1, "Speak to Me", "0:1:8");
			album.AddTrack(2, "Breathe", "0:3:57");
			album.AddTrack(3, "On the Run", "0:3:51");
			album.AddTrack(4, "Time", "0:5:54");
			album.AddTrack(5, "The Great Gig in the Sky", "0:4:47");
			album.AddTrack(6, "Money", "0:6:23");
			album.AddTrack(7, "Us and Them", "0:7:48");
			album.AddTrack(8, "Any Colour You Like", "0:3:25");
			album.AddTrack(9, "Brain Damage", "0:3:50");
			album.AddTrack(10, "Eclipse", "0:2:06");

			albums.Add(album);

			/*
			 * Battle for the Sun
			 * 
			 */
			album = new Album()
			{
				Title = "Battle for the Sun",
				Author = "Placebo",
				Genre = "Sux",
				Label = "Play It Again Sam",
				PublicationDate = new DateTime(2009, 6, 8)
			};

			album.AddTrack(1, "Kitty Litter", "0:3:47");
			album.AddTrack(2, "Ashtray Heart", "0:3:32");
			album.AddTrack(3, "Battle for the Sun", "0:5:32");
			album.AddTrack(4, "For What It's Worth", "0:2:47");
			album.AddTrack(5, "Devil in the Details", "0:4:28");
			album.AddTrack(6, "Bright Lights", "0:3:23");
			album.AddTrack(7, "Speak in Tongues", "0:4:06");
			album.AddTrack(8, "The Never-Ending Why", "0:3:23");
			album.AddTrack(9, "Julien", "0:4:43");
			album.AddTrack(10, "Happy You're Gone", "0:3:50");
			album.AddTrack(11, "Breathe Underwater", "0:3:44");
			album.AddTrack(12, "Come Undone", "0:4:36");
			album.AddTrack(13, "Kings of Medicine", "0:4:15");

			albums.Add(album);

			/*
			 * Chronicle, Vol. 1
			 * 
			 */
			album = new Album()
			{
				Title = "Chronicle, Vol. 1",
				Author = "Creedence Clearwater Revival",
				Genre = "Rock",
				Label = "Fantasy Records",
				PublicationDate = new DateTime(1976, 6, 8)
			};

			album.AddTrack(1, "Susie Q", "0:4:35");
			album.AddTrack(2, "I Put a Spell on You", "0:4:30");
			album.AddTrack(3, "Proud Mary", "0:3:07");
			album.AddTrack(4, "Bad Moon Rising", "0:2:18");
			album.AddTrack(5, "Lodi", "0:3:09");
			album.AddTrack(6, "Green River", "0:2:32");
			album.AddTrack(7, "Commotion", "0:2:41");
			album.AddTrack(8, "Down on the Corner", "0:2:43");
			album.AddTrack(9, "Fortunate Son", "0:2:18");
			album.AddTrack(10, "Travelin' Band", "0:2:07");
			album.AddTrack(11, "Who'll Stop the Rain", "0:2:27");
			album.AddTrack(12, "Up Around the Bend", "0:2:41");
			album.AddTrack(13, "Run Through the Jungle", "0:3:05");
			album.AddTrack(14, "Lookin' Out My Back Door", "0:2:31");
			album.AddTrack(15, "Long as I Can See the Light", "0:3:32");
			album.AddTrack(16, "I Heard It Through the Grapevine", "0:11:04");
			album.AddTrack(17, "Have You Ever Seen the Rain?", "0:2:38");
			album.AddTrack(18, "Hey Tonight", "0:2:41");
			album.AddTrack(19, "Sweet Hitch-Hiker", "0:2:55");
			album.AddTrack(20, "Someday Never Comes", "0:3:59");
			albums.Add(album);

			/*
			 * Led Zeppelin
			 * 
			 */
			album = new Album()
			{
				Title = "Led Zeppelin",
				Author = "Led Zeppelin",
				Genre = "Rock",
				Label = "Atlantic Records",
				PublicationDate = new DateTime(1969, 1, 12)
			};

			album.AddTrack(1, "Good Times, Bad Times", "0:2:47");
			album.AddTrack(2, "Babe I'm Gonna Leave You", "0:6:41");
			album.AddTrack(3, "You Shook Me", "0:6:27");
			album.AddTrack(4, "Dazed and Confused", "0:6:26");
			album.AddTrack(5, "Your Time Is Gonna Come", "0:4:34");
			album.AddTrack(6, "Black Mountain Side", "0:2:12");
			album.AddTrack(7, "Communication Breakdown", "0:2:29");
			album.AddTrack(8, "I Can't Quit You Baby", "0:4:42");
			album.AddTrack(9, "How Many More Times", "0:8:28");
			albums.Add(album);

			/*
			 * Powerslave
			 * 
			 */
			album = new Album()
			{
				Title= "Powerslave",
				Author = "Iron Maiden",
				Genre = "Metal",
				Label = "EMI",
				PublicationDate = new DateTime(1984, 9, 3)
			};


			album.AddTrack(1, "Aces High", "0:4:32");
			album.AddTrack(2, "2 Minutes to Midnight", "0:6:04");
			album.AddTrack(3, "Losfer Words (Big 'Orra)", "0:4:15");
			album.AddTrack(4, "Flash of the Blade", "0:4:06");
			album.AddTrack(5, "The Duellists", "0:6:07");
			album.AddTrack(6, "Back in the Village", "0:5:03");
			album.AddTrack(7, "Powerslave", "0:7:11");
			album.AddTrack(8, "Rime of the Ancient Mariner", "0:13:37");

			albums.Add(album);

			albums.AddRange(CreateTestAlbums());

			return albums;
		}
	}
}
